/********************************
*
* This is an alternate version of StudentRegistrationSystem.java, 
* based on v64 in src directory.
*
* It's been modified to use private methods and private instance
* variables, in place of static methods and parameter passing.
*
* Also modified the "switch" statement to use integer, instead of
* string, for backward-compatability with earlier versions of
* Java (e.g. Java SE 6).
*
* Sara
*
*********************************/

import java.util.*;    // ArrayList, Collections, Comparator, Scanner, TreeSet
import java.io.*;      // File, FileNotFoundException, IOException
import java.lang.*;    // 
import org.apache.commons.lang3.StringUtils; 

public class StudentRegistrationSystem {

	private ArrayList<Student> studentList = new ArrayList<Student>();
	private ArrayList<Course>  courseList  = new ArrayList<Course>();
	private Student student;

	/**
	* main()
	*/
	public static void main(String args[]) {
		new StudentRegistrationSystem().run();
	}

	/**
	* main()
	*/
	public void run() {
		String  selection;

		Scanner userInput = new Scanner(System.in);

		clearScreen();
		String WELCOME_MESSAGE = "##### Team C: Student Registration System #####";
		System.out.println("\n" + WELCOME_MESSAGE + "\n");

		// Display Course List
		courseList = CourseList.readCourseList("CourseList.txt");
		displayCourseList();

		// Student List
		studentList = StudentList.readStudentList("StudentList.txt", courseList);
		//System.out.println(studentList);

		// Student Login
		// Option 1 (user prompt without menu)
		//student = loginStudent();
		//if (student != null) {
		//	System.out.println("Registerd Student");
		//} else {
		//	createStudentAccount();
		//}

		// Option 2 (user prompt with menu selection)
		System.out.println("Menu:");
		System.out.println("1. Login");
		System.out.println("2. Create New Account");
		System.out.println("3. Exit");
		System.out.println("");
		System.out.print("Enter your selection: ");
		selection = userInput.next();

		switch ( Integer.parseInt(selection) ) {
		case 1:
			loginStudent();
			break;
		case 2:
			createStudentAccount();
			break;
		case 3:
			System.exit(0);
		default:
			System.out.println("Invalid selection.");
			break;
		}

		System.out.println("");
	}

	/**
	* displayCourseList()
	*/
	private void displayCourseList() {

		for (int i=0; i < courseList.size(); i++) {
			System.out.println(courseList.get(i));
		}
	}

	/**
	* createStudentAccount()
	*/
	private void createStudentAccount() {
		System.out.println("=== createStudentAccount() ==="); //debug
		String loginName;

		Scanner userLogin = new Scanner(System.in);

		System.out.print("Enter new login name: ");
		loginName = userLogin.next();
		System.out.println("Creating new login name " + loginName);
	}

	/**
	* loginStudent()
	*/
	private void loginStudent() {
		System.out.println("=== loginStudent() ==="); //debug
		Boolean            loginStatus   = false;
		String             loginName     = "";

		Scanner userLogin = new Scanner(System.in);

		System.out.print("Enter your login name: ");
		loginName = userLogin.next();

		student = StudentList.getStudent(loginName, studentList);
		System.out.println(student);
	}

	/**
	* readCourseList()
	*/
	private void readCourseList() {
		System.out.println("=== readCourseList() placeholder ===");
	}

	/**
	* writeCourseList()
	*/
	private void writeCourseList() {
		System.out.println("=== writeCourseList() placeholder ===");
	}

	/**
  	* clearScreen()
  	*/
  	private void clearScreen() {
    	try {
      		if (System.getProperty( "os.name" ).startsWith( "Window" )) {
        		Runtime.getRuntime().exec("cls");
      		} else {
        		Runtime.getRuntime().exec("clear");
      		}
    	} catch (IOException e) {
      		for(int i = 0; i < 100; i++) {
        		System.out.println();
      		}
		}
	}

}
